package org.example.game.history;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/12 10:32
 */
public class Solution100296 {

    public static void main(String[] args) {
        Solution100296 solution100296 = new Solution100296();
        System.out.println(solution100296.findPermutationDifference("abc", "bac"));
    }

    public int findPermutationDifference(String s, String t) {

        int sum = 0;

        HashMap<Character, Integer> sMap = new HashMap<>();

        int index = 0;
        for(Character c : s.toCharArray()){
            sMap.put(c, index);
            index++;
        }

        index = 0;
        for(Character c : t.toCharArray()){
            if(sMap.containsKey(c)){
                sum += Math.abs( sMap.get(c) - index);
            }
            index++;
        }

        return sum;

    }

}
